/******************************************************************************************************************
* File:SystemA.java
*
* Description:
*
* This class contains the entry point for System A, the main method which instantiates the filters 
* required for the system to run. It calls the connect method from FilterFramework2 to connect
* the ports of the filters together. It is used to set the parameters and to structure the pipe
* and filter system. Once the entire system is set up, a thread is started for each filter
*
* Parameters: 		Source File name
*
*@author Team 10
*
******************************************************************************************************************/
public class SystemA extends SystemSuperClass
{
   public static void main( String argv[])
   {
	   
	   String filename = null;
	   try
	   {
	   //setting the filename to the command line argument.
		   
	   filename = argv[0];
	   
	   } 	catch (ArrayIndexOutOfBoundsException e){
			System.out.println("Correct Usage: java SystemB <sourcefile>"); //printing the correct usage of the command
			System.exit(1);
		}
	   
	   //This static method call determines the frame length to handle the case
	   //when different files have varying frame lengths
	   
	    determineFrameLength(filename);
	   
		/****************************************************************************
		* Here we instantiate the four filters needed for System A
		****************************************************************************/
	    
	    
	    SourceFilter Filter1 = new SourceFilter(filename);   // Source Filter
		AltitudeFilter altFilter=new AltitudeFilter();       // Altitude Filter, converts feet to meters
		TemperatureFilter tempFilter=new TemperatureFilter();// Temperature filter, converts Fahrenheit to Celsius
		
		// Passing the order format of the output to be written into the file.
		
		SinkFilter Filter3 = new SinkFilter(new int[]{0, 4, 2},"OutputA.dat"); 
		
		
		/****************************************************************************
		* Connecting the filters together
		****************************************************************************/
		
		altFilter.Connect(Filter1, 0, 0);      // Connect first input port of Altfilter to first output port of SourceFilter
		tempFilter.Connect(altFilter, 0, 0);
		Filter3.Connect(tempFilter, 0, 0);
		
		/****************************************************************************
		* Here we start threads for each of the filters
		****************************************************************************/

		Filter1.start();
		altFilter.start();
		tempFilter.start();
		Filter3.start(); 
	
   } // main

} // System A